<template>
    <view class="select_office_input_cp">
        <u-input 
            v-model="office" 
            type="select" 
            @click="show = true"
            placeholder="请选择科室"/>
        <u-select
            v-model="show" 
            :list="officeList" 
            @confirm="confirm">
        </u-select>
    </view>
</template>

<script>
//科室选择input组件
import {findSectionRooms} from "@/common/api"
export default {
    name:"SelectOfficeInputCp",
    props:{
        value:{
            type:String,
            default:'',
        },
    },
    data() {
        return {
            show: false,
            officeList: [],
        }
    },
    computed:{
        office:{ //科室
            get(){
                return this.value;
            },
            set(value){
                this.$emit('input',value);
            },
        },
    },
    created(){
        this.getData();
    },
    methods:{
        confirm(e){ //确定按钮点击事件            
            this.office = e[0].label;
            this.officeList.forEach(item=>{
                if(item.value == e[0].value){
                    this.$emit('change',item.baseData); //返回所选择的原始数据
                }
            });
        },
        getData(){ //获取科室列表
            findSectionRooms(
                {},
            ).then(data=>{
                this.officeList = [];
                data.forEach(item=>{
                    this.officeList.push({
                        value:item.Sid,
                        label:item.Sname,
                        baseData:item,
                    });
                });
            });
        },
    },
}
</script>

<style lang="scss" scoped>
.select_office_input_cp {
    text-align: center;
    width: 100%;
    /deep/.u-input{
        width: 100%;
    }
}
</style>
